<template>
  <div>
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>订单管理</el-breadcrumb-item>
      <el-breadcrumb-item>订单列表</el-breadcrumb-item>
    </el-breadcrumb>

    <el-card>
      <!-- 搜索-->
      <el-row :gutter="20">
        <el-col :span="8">
          <!-- clearable 清空 -->
          <el-input placeholder="请输入内容" v-model="queryInfo.query" clearable @clear="getOrderList">
          <el-button slot="append" icon="el-icon-search" @click="getOrderList"></el-button>
          </el-input>
        </el-col>
      </el-row>

      <el-table :data="orderList" border stripe>
        <el-table-column type="index"></el-table-column>
        <el-table-column prop="order_number" label="订单编号"></el-table-column>
        <el-table-column prop="order_price" label="订单价格" width="120px"></el-table-column>
        <el-table-column prop="pay_status" label="是否付款" width="90px"></el-table-column>
        <el-table-column label="是否发货" width="120px">
          <template slot-scope="scope">
            <el-tag type="danger" size="small" v-if=" scope.row.pay_status === '0' ">未付款</el-tag>
            <el-tag size="small" v-else-if=" scope.row.pay_status === '1' ">已付款</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="create_time" label="时间" width="180px">
          <template slot-scope="scope">
            {{ scope.row.create_time | dateFormat }}
          </template>
        </el-table-column>
        <el-table-column label="操作" width="180px">
          <template slot-scope="scope">
            <el-tooltip content="修改地址" placement="top" :enterable="false">
              <el-button type="primary" size="mini" icon="el-icon-edit" @click="showEditDialog"></el-button>
            </el-tooltip>
            <el-tooltip content="物流信息" placement="top" :enterable="false">
              <el-button type="success" size="mini" icon="el-icon-truck" @click="showprogressDialog"></el-button>
            </el-tooltip>
            <el-button type="danger" size="mini" icon="el-icon-delete" @click="removeGoodById(scope.row.goods_id)"></el-button>
          </template>
        </el-table-column>
      </el-table>

      <!-- 分页 -->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="queryInfo.pagenum"
        :page-sizes="[3, 5, 10, 15]"
        :page-size="queryInfo.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total">
      </el-pagination>

    </el-card>

    <!-- 修改对话框 -->
    <el-dialog
      title="修改地址"
      :visible.sync="editDialogVisible"
      width="50%"
      @close="editDialogClosed"
      >
      <!-- 修改参数对话框 -->
      <el-form :model="addressForm" :rules="addressFormRules" ref="addressFormRef" label-width="100px">
        <el-form-item label="省市区/县" prop="address1">
          <el-cascader
            :options="cityData"
            v-model="addressForm.address1"
            clearable
          >
          </el-cascader>
        </el-form-item>
        <el-form-item label="详细地址" prop="address2">
          <el-input v-model="addressForm.address2"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="editDialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="editOrder">确 定</el-button>
      </span>
    </el-dialog>


    <!-- 物流信息对话框 -->
    <el-dialog
      title="物流信息"
      :visible.sync="progressDialogVisible"
      width="50%"
      >
      <el-timeline :reverse="reverse">
        <el-timeline-item
          v-for="(activity, index) in activities"
          :key="index"
          :timestamp="activity.timestamp">
          {{activity.content}}
        </el-timeline-item>
      </el-timeline>
    </el-dialog>

  </div>
</template>
<script>
import cityData from './citydata.js'; // 引入城市级联数据
export default {
  data() {
    return {
      queryInfo: {
        query: '',
        pagenum: 1,
        pagesize: 10
      },
      orderList: [],
      total: 0,
      editDialogVisible: false,
      addressForm: {
        address1: [], // 级联选择器
        address2: ''
      },
      addressFormRules: {  // 添加表单验证规则
        address1: [
          { required: true, message: '请选择省市县', trigger: 'blur' },
        ],
        address2: [
          { required: true, message: '请输入详细地址', trigger: 'blur' },
        ]
      },
      cityData,
      progressDialogVisible: false,
      progressInfo: [],


      reverse: true,
      activities: [{
        content: '您的快件已签收，如有疑问请电联快递员【郑成逢，电话：13540875247】。疫情期间顺丰每日对网点消毒、快递员每日测温、配戴口罩，感谢您使用顺丰，期待再次为您服务。（主单总件数：1件）',
        timestamp: '2022-03-17 10:37'
      }, {
        content: '快件交给郑成逢,正在派送途中（联系电话：13540875247,顺丰已开启“安全呼叫”保护您的电话隐私,请放心接听！）（主单总件数：1件）',
        timestamp: '2022-03-17 10:37'
      }, {
        content: '快件到达 【成都温江科林路速运营业部】',
        timestamp: '2022-03-17 06:39'
      }]
    }
  },
  created() {
    this.getOrderList();
  },
  methods: {
    async getOrderList() {
      const {data: res} = await this.$http.get('orders', { params: this.queryInfo });
      if(res.meta.status != 200) return this.$message.error('获取订单失败');
      this.orderList = res.data.goods;
      this.total = res.data.total;
    },

    handleSizeChange(newSize) {  // 监听pagesize改变
      this.queryInfo.pagesize = newSize;
      this.getOrderList();
    },
    handleCurrentChange(newPage) { // 监听pagenum改变
      this.queryInfo.pagenum = newPage;
      this.getOrderList();
    },
    showEditDialog() {
      this.editDialogVisible = true;
    },
    editDialogClosed() {
      this.$refs.addressFormRef.resetFields();
    },
    editOrder() {

    },
    async showprogressDialog() {  // 物流信息
      // this.$message.error('获取物流接口失效');
      this.progressDialogVisible = true;

      
      return false;
      const {data: res} = await this.$http.get('/kuaidi/804909574412544580');
      console.log(res);
      if(res.meta.status != 200) return this.$message.error('获取物流信息失败');
      this.progressInfo = res.data;
    },
    
  }
}
</script>
<style lang="less" scoped>
  .el-cascader{width: 100%;}
</style>
